package com.eso.haBank.controller

import com.eso.haBank.domain.Customization

class CustomizationController {

    static allowedMethods = [update: "POST"]

    def userAuthService;
    def customizationService;

    def index() {
        redirect(action: "initial", params: params)
    }

    def initial = {
        def appCustomizeList = Customization.createCriteria().list(params){
            order('customizeType', 'asc')
        };

        [appCustomizeList: appCustomizeList]
    }

    def update = {

        def resultCode = 0;
        def currUser = userAuthService.getUser(session);

        try{
            Customization.list().each {customizationInstance ->
                customizationInstance.customizeValue = params["customizeValue_${customizationInstance.customizeType}"];
                customizationInstance.updateUser = currUser.userName;

                customizationInstance.save(flush: true);
            }

            //重新加载个性化配置缓存
            customizationService.loadAppCustomizeData();

            resultCode = 1;
        }catch (Exception e){
            resultCode = 0;
            log.info e;
        }
        [resultCode: resultCode];
    }
}
